<?php
if(ENVIRONMENT == "DEVELOPMENT")
{
	/*
	Compile CSS Less
	----------------
	Compile files within /assets/css/less for deployment.
	*/
	// Set initial directory
	$vDirectory    = './assets/css/';
	$vCSSLessFiles = scandir($vDirectory.'less/');

	$vFileName='screen';

	// Run Compile
	compile_less($vFileName.'.less',$vFileName.'.css');
}

function compile_less($vLessFileName, $vCSSFileName)
{
	// Load the cache
	$vCacheFileName = '.'.ASSETS_CSS.'less/cache/'.$vLessFileName.".cache";
	
	// Set directories on filenames
	$vLessFileName = '.'.ASSETS_CSS.'less/'.$vLessFileName;
	$vCSSFileName = '.'.ASSETS_CSS.'lib/'.$vCSSFileName;
	
	// Check if we have a cache, if so, pull the data for change check
	if (file_exists($vCacheFileName)) {
		$oCache = unserialize(file_get_contents($vCacheFileName));
	} else {
		$oCache = $vLessFileName;
	}
	
	// Read the files by compiling
	$oNewCache = lessc::cexecute($oCache);
	if (!is_array($oCache) || $oNewCache['updated'] > $oCache['updated']) {
		// Create new cache
		file_put_contents($vCacheFileName, serialize($oNewCache));
		
		// Create the CSS
		file_put_contents($vCSSFileName, $oNewCache['compiled']);
	}
}
?>